using System;
using System.Linq;
using CommandSystem;
using Exiled.API.Features;
using RgCore.PlayerHud;

namespace RgCore.Commands
{
    public class AdminBroadcastCommand : ICommand, IUsageProvider
    {
        public string[] Aliases => new string[] { "bc", "alert" };

        public string Command => "broadcast";

        public string Description => "发送公告";

        public string[] Usage => new string[]
        {
            "时长(秒)",
            "内容",
        };

        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            if (sender.CheckPermission(PlayerPermissions.Broadcasting))
            {
                if (arguments.Count < 2)
                {
                    response = "用法：bc <时长(秒)> <内容> --请不要输入太多内容！";
                    return false;
                }

                if (ushort.TryParse(arguments.At(0), out ushort second))
                {
                    string text = string.Empty;
                    foreach (string str in arguments.Skip(1))
                        text += str + " ";
                    foreach (Player player in Player.List)
                        player.SendFormattedMsg("admin_announce", "<color=#00FFFF>管理公告</color>",
                            $"<color=#00FF00>{((CommandSender)sender).Nickname}</color>: {text.Replace('<', '[').Replace('>', ']')}", second, MsgType.Announcement,
                            ScreenLocation.CenterTop, true);
                    response = "已发送成功！";
                    return true;
                }
                else
                {
                    response = "请输入一个合法的数字(时间)";
                    return false;
                }
            }
            else
            {
                response = "你没有使用全服公告的权限！";
                return false;
            }
        }
    }
}